package controller

import (
	"context"
	"github.com/gin-gonic/gin"
	"net/http"
	"user_bff/forms"
	"user_bff/pkg"
	"user_bff/user_proto"
)

// 修改用户信息
func UpdateUserInfo(c *gin.Context) {
	var form forms.UpdateUserInfoForm
	if err := c.ShouldBind(&form); err != nil {
		ReturnErrorJson(err, c)
		return
	}
	comment := pkg.Comment()
	_, err := comment.UpdateUserInfo(context.Background(), &user_proto.UpdateUserInfoRequest{
		Id:       int64(form.Id),
		NickName: form.NickName,
		Mobile:   form.Mobile,
		Password: form.Password,
		BirthDay: form.BirthDay,
		Sex:      int64(form.Sex),
		Age:      int64(form.Age),
	})
	if err != nil {
		c.JSON(http.StatusNotFound, gin.H{
			"code": -1,
			"msg":  "修改用户信息失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "修改用户信息成功",
		"data": nil,
	})
	return
}
